@file:Suppress("unused", "NOTHING_TO_INLINE", "FunctionName")

package top.techqi.core.kext

/* ========== ========== ========== ========== ========== ========== ==========
 * ========== ========== ========== = concat = ========== ========== ==========
 * ========== ========== ========== ========== ========== ========== ========== */

/* ---------- ---------- Single Word ---------- ---------- */

inline fun WORD(hByte: Int, lByte: Int): Int {
    return ((hByte and 0xFF) shl 8) or (lByte and 0xFF)
}

/* ---------- ---------- Double Word ---------- ---------- */

inline fun DWORD(hWord: Int, lWord: Int): Int {
    return ((hWord and 0xFFFF) shl 16) or (lWord and 0xFFFF)
}

inline fun DWORD(hhByte: Int, hlByte: Int, lhByte: Int, llByte: Int): Int {
    return DWORD(WORD(hhByte, hlByte), WORD(lhByte, llByte))
}

/* ---------- ---------- Quadra Word ---------- ---------- */

inline fun QWORD(hDWord: Int, lDWord: Int): Long {
    return (hDWord.toLong() shl 32) or lDWord.toLong()
}

inline fun QWORD(hhWord: Int, hlWord: Int, lhWord: Int, llWord: Int): Long {
    return QWORD(DWORD(hhWord, hlWord), DWORD(lhWord, llWord))
}

inline fun QWORD(
    hhhByte: Int, hhlByte: Int, hlhByte: Int, hllByte: Int,
    lhhByte: Int, lhlByte: Int, llhByte: Int, lllByte: Int
): Long {
    return QWORD(
        DWORD(hhhByte, hhlByte, hlhByte, hllByte),
        DWORD(lhhByte, lhlByte, llhByte, lllByte)
    )
}

/* ========== ========== ========== ========== ========== ========== ==========
 * ========== ========== ========== = divide = ========== ========== ==========
 * ========== ========== ========== ========== ========== ========== ========== */

/* ---------- ---------- Single Word ---------- ---------- */

inline val Int.hByte: Int
    get() = ((this shr 8) and 0xFF)

inline val Int.lByte: Int
    get() = ((this shr 0) and 0xFF)

/* ---------- ---------- Double Word ---------- ---------- */

inline val Int.hWord: Int
    get() = ((this shr 16) and 0xFFFF)

inline val Int.lWord: Int
    get() = ((this shr 0) and 0xFFFF)

inline val Int.hhByte: Int
    get() = ((this shr 24) and 0xFF)

inline val Int.hlByte: Int
    get() = ((this shr 16) and 0xFF)

inline val Int.lhByte: Int
    get() = ((this shr 8) and 0xFF)

inline val Int.llByte: Int
    get() = ((this shr 0) and 0xFF)

/* ---------- ---------- Quadra Word ---------- ---------- */

inline val Long.hDWord: Int
    get() = ((this shr 32) and 0xFFFFFFFFL).toInt()

inline val Long.lDWord: Int
    get() = ((this shr 0) and 0xFFFFFFFFL).toInt()

inline val Long.hhWord: Int
    get() = ((this shr 48) and 0xFFFF).toInt()

inline val Long.hlWord: Int
    get() = ((this shr 32) and 0xFFFF).toInt()

inline val Long.lhWord: Int
    get() = ((this shr 16) and 0xFFFF).toInt()

inline val Long.llWord: Int
    get() = ((this shr 0) and 0xFFFF).toInt()

inline val Long.hhhByte: Int
    get() = ((this shr 56) and 0xFF).toInt()

inline val Long.hhlByte: Int
    get() = ((this shr 48) and 0xFF).toInt()

inline val Long.hlhByte: Int
    get() = ((this shr 40) and 0xFF).toInt()

inline val Long.hllByte: Int
    get() = ((this shr 32) and 0xFF).toInt()

inline val Long.lhhByte: Int
    get() = ((this shr 24) and 0xFF).toInt()

inline val Long.lhlByte: Int
    get() = ((this shr 16) and 0xFF).toInt()

inline val Long.llhByte: Int
    get() = ((this shr 8) and 0xFF).toInt()

inline val Long.lllByte: Int
    get() = ((this shr 0) and 0xFF).toInt()
